<template>
  <div>
    <el-dialog
      title="角色变更"
      :visible="isShow"
      width="500px"
      @close="cancelEvent"
    >
      <el-checkbox-group v-model="value">
        <el-checkbox v-for="item in list" :key="item.id" :label="item.id">{{
          item.name
        }}</el-checkbox>
      </el-checkbox-group>
      <template #footer>
        <div style="text-align: center">
          <el-button type="primary" @click="submit">提交</el-button>
          <el-button @click="cancelEvent">取消</el-button>
        </div>
      </template>
    </el-dialog>
  </div>
</template>

<script>
import { sysRole } from '@/api/setting'
import { sysUser } from '@/api/login'
import { sysUserAssignRoles } from '@/api/premission'
export default {
  props: {
    isShow: {
      type: Boolean,
      default: false
    }
  },
  isShow: false,
  data() {
    return {
      list: [],
      value: [],
      id: ''
    }
  },
  created() {
    this.getData()
  },
  methods: {
    cancelEvent() {
      this.$emit('update:isShow', false)
      this.value = []
    },
    async getData() {
      const res = await sysRole({
        page: 1,
        pagesize: 1000
      })
      this.list = res.data.rows
      console.log('角色列表数据', res)
    },
    async getUserInfo(id) {
      this.id = id
      const res = await sysUser(id)

      this.value = res.data.roleIds
      console.log('用户详情', res)
    },
    // 修改用户角色
    async submit() {
      await sysUserAssignRoles(this.id, this.value)
      this.$message.success('修改用户角色成功')
      this.cancelEvent()
    }
  }
}
</script>

<style></style>
